//
//  LZMyRestaurantInfoHeaderView.m
//  laziz_Merchant
//
//  Created by ZhaoDongBo on 2016/12/19.
//  Copyright © 2016年 XBN. All rights reserved.
//

#import "LZMyRestaurantInfoHeaderView.h"
#import "Masonry.h"

@implementation LZMyRestaurantInfoHeaderView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.backgroundColor = UIColorFromRGB(0xffffff, 1);
        self.userInteractionEnabled = YES;
        
        [self configView];
        [self addAutoLayoutToCell];
        
        UITapGestureRecognizer * tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGR:)];
        [self addGestureRecognizer:tapGR];
    }
    return self;
}

- (void)configView {
    [self addSubview:self.titleLabel];
    [self addSubview:self.subLabel];
    [self addSubview:self.line];
    [self addSubview:self.accessoryImageView];
}

- (void)addAutoLayoutToCell {
    
    WS(weakSelf);
    
    [self.titleLabel makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(weakSelf.mas_centerY);
        make.leading.mas_equalTo(10);
    }];
    
    [self.subLabel makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(weakSelf.mas_centerY);
        make.trailing.mas_lessThanOrEqualTo(weakSelf.accessoryImageView.mas_leading).with.offset(-10);
    }];

    [self.line makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(0);
        make.leading.mas_equalTo(10);
        make.trailing.mas_equalTo(-10);
        make.height.mas_equalTo(0.6);
    }];
    
    [self.accessoryImageView makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(weakSelf.titleLabel.mas_centerY);
        make.trailing.mas_equalTo(-10);
        make.size.mas_equalTo(CGSizeMake(6, 12));
    }];
}

- (void)tapGR:(UITapGestureRecognizer *)sender {
    if (self.delegate) {
        [self.delegate tapHeaderViewAddGroupOrderAction];
    }
}

- (UILabel *)titleLabel {
    
    if (_titleLabel == nil) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.textColor   = UIColorFromRGB(0x333333, 1);
        _titleLabel.font        = [UIFont systemFontOfSize:15];
        _titleLabel.text = LZLocalizedString(@"object_of_the_group_order_title", nil);
    }
    
    return _titleLabel;
}

- (UILabel *)subLabel {
    
    if (_subLabel == nil) {
        _subLabel = [[UILabel alloc] init];
        _subLabel.textColor        = UIColorFromRGB(0x999999, 1);
        _subLabel.font             = [UIFont systemFontOfSize:14];
        _subLabel.text = LZLocalizedString(@"add", nil);
    }
    
    return _subLabel;
}

- (UIView *)line {
    
    if (_line == nil) {
        _line = [[UIView alloc] init];
        _line.backgroundColor = UIColorFromRGB(0xeeeeee, 1);
    }
    
    return _line;
}

- (UIImageView *)accessoryImageView {
    
    if (_accessoryImageView == nil) {
        _accessoryImageView = [[UIImageView alloc] init];
        if ([[LZLanguageManager shareInstance] getLanguageType] == LanguageType_Ar) {
            _accessoryImageView.image = [UIImage imageNamed:@"lz_cell_accessoryimage_ar"];
        } else {
            _accessoryImageView.image = [UIImage imageNamed:@"lz_cell_accessoryimage_en"];
        }
    }
    
    return _accessoryImageView;
}

@end
